package com.gxkj.projects.myshopx.dao;

import com.gxkj.common.hibernate.HibernateBaseRepositoryImpl;
import com.gxkj.common.utils.ListPager;
import com.gxkj.projects.myshopx.entitys.Category;
import com.gxkj.projects.myshopx.entitys.DbConfig;
import com.gxkj.projects.myshopx.entitys.Goods;
import com.gxkj.projects.myshopx.enums.CategoryState;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据库配置表
 */
@Repository
public class DbConfigDaoImpl  extends HibernateBaseRepositoryImpl {

    public List<DbConfig> loadAll(){
        String hql = "from DbConfig";
        return this.selectListByHQL(hql,null);
    }

    public boolean isExitByName(String id,String proName ){
        String hql = null;
        Map<String,Object> param = new HashMap<String,Object>();
        hql = " from DbConfig a where proName = :proName ";

        param.put("proName",proName);

        if( StringUtils.isEmpty(id)){

        }else {
            hql += "  and id != :id";
            param.put("id",id);
        }
        DbConfig entity = this.selectFirstOneByHQL(hql,param);
        if(entity == null){
            return false;
        }else {
            return true;
        }

    }

    public ListPager<DbConfig> doPageHQL(int pagenNo, int pageSize, DbConfig entity){
        ListPager<DbConfig> pager = new ListPager<DbConfig>();
        pager.setPageNo(pagenNo);
        pager.setRowsPerPage(pageSize);
        String hql  = " from DbConfig c   ";
//        Map<String,Object> param = new HashMap<String,Object>();

        return  this.selectPageByHql(hql,null,pager);
    }
}
